#ifdef __DEBUG_PRINTF__
/*
*
* Some Debug printf kit for devlopment 
*
* Date   : 2019.09.05
*
* Editor : Schips
*
* version : 
*
*    2019.09.12 : add perror about.
*
*    2019.09.05 : add conditional printf.
*
*    2019.03.04 : base version.
*/

#if 0
Usage：
    define  "__DEBUG_PRINTF__" or "  __CDEBUG_PRINTF__" or both
    define  "__DEBUG_PERROR__" or " __CDEBUG_PERROR__"  or both
#endif

#include <stdio.h>
/* Debug printf infomration with color. */
#define DEBUG(format,...)           printf(""format"\n",  ##__VA_ARGS__ )
#define DEBUG_RED(format,...)       printf("\033[30m\033[31m"format"\033[0m\n", ##__VA_ARGS__)
#define DEBUG_GREEN(format,...)     printf("\033[30m\033[32m"format"\033[0m\n", ##__VA_ARGS__)
#define DEBUG_YELLOW(format,...)    printf("\033[30m\033[33m"format"\033[0m\n", ##__VA_ARGS__)
#define DEBUG_PURP(format,...)      printf("\033[30m\033[35m"format"\033[0m\n", ##__VA_ARGS__)
#define DEBUG_BLUE(format,...)      printf("\033[30m\033[36m"format"\033[0m\n", ##__VA_ARGS__)


/* Debug with file name and line. */
#define DEBUG_FL(format,...)        printf("["__FILE__"](%05d) - %s]\n  "format"\n", __LINE__, ##__VA_ARGS__ ,  __FUNCTION__)

#define DEBUG_FLR(format,...)       printf("\033[30m\033[31m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_FLG(format,...)       printf("\033[30m\033[32m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_FLY(format,...)       printf("\033[30m\033[33m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_FLP(format,...)       printf("\033[30m\033[35m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_FLB(format,...)       printf("\033[30m\033[36m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)


/* Debug with file name and line in function. */
#define DEBUG_SFL(format,...)       printf("["__FILE__"](%05d) - %s]  "format"\n", __LINE__, ##__VA_ARGS__ ,  __FUNCTION__)
#define DEBUG_SFLR(format,...)      printf("\033[30m\033[31m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_SFLG(format,...)      printf("\033[30m\033[32m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_SFLY(format,...)      printf("\033[30m\033[33m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_SFLP(format,...)      printf("\033[30m\033[35m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)
#define DEBUG_SFLB(format,...)      printf("\033[30m\033[36m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__)

#define SC_CLEAR() printf("\033[2J")

#else /* __DEBUG_PRINTF__ */

#define DEBUG(format,...)
#define DEBUG_RED(format,...)
#define DEBUG_GREEN(format,...)
#define DEBUG_YELLOW(format,...)
#define DEBUG_PURP(format,...)
#define DEBUG_BLUE(format,...)

#define DEBUG_FL(format,...)
#define DEBUG_FLR(format,...)
#define DEBUG_FLG(format,...)
#define DEBUG_FLY(format,...)
#define DEBUG_FLP(format,...)
#define DEBUG_FLB(format,...)

#define DEBUG_SFL(format,...)
#define DEBUG_SFLR(format,...)
#define DEBUG_SFLG(format,...)
#define DEBUG_SFLY(format,...)
#define DEBUG_SFLP(format,...)
#define DEBUG_SFLB(format,...)
#define SC_CLEAR(format,...)
#endif /* __DEBUG_PRINTF__ */

#ifdef __CDEBUG_PRINTF__

#include <stdio.h>
/* Debug with file name and line. */
#define CDEBUG(       cmdt, format,...)   do{if((cmdt)) printf(""format"\n",  ##__VA_ARGS__ ); }while(0)
#define CDEBUG_RED(   cmdt, format,...)   do{if((cmdt)) printf("\033[30m\033[31m"format"\033[0m\n", ##__VA_ARGS__);}while(0)
#define CDEBUG_GREEN( cmdt, format,...)   do{if((cmdt)) printf("\033[30m\033[32m"format"\033[0m\n", ##__VA_ARGS__);}while(0)
#define CDEBUG_YELLOW(cmdt, format,...)   do{if((cmdt)) printf("\033[30m\033[33m"format"\033[0m\n", ##__VA_ARGS__);}while(0)
#define CDEBUG_PURP(  cmdt, format,...)   do{if((cmdt)) printf("\033[30m\033[35m"format"\033[0m\n", ##__VA_ARGS__);}while(0)
#define CDEBUG_BLUE(  cmdt, format,...)   do{if((cmdt)) printf("\033[30m\033[36m"format"\033[0m\n", ##__VA_ARGS__);}while(0)


/* Debug printf infomration with color. */
#define CDEBUG_FL(cmdt, format,...)        do{if((cmdt))printf("["__FILE__"](%05d) - %s]\n  "format"\n", __LINE__, ##__VA_ARGS__ ,  __FUNCTION__);}while(0)

#define CDEBUG_FLR(cmdt, format,...)       do{if((cmdt))printf("\033[30m\033[31m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_FLG(cmdt, format,...)       do{if((ccmdt)printf("\033[30m\033[32m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_FLY(cmdt, format,...)       do{if((ccmdt)printf("\033[30m\033[33m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_FLP(cmdt, format,...)       do{if((ccmdt)printf("\033[30m\033[35m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_FLB(cmdt, format,...)       do{if((ccmdt)printf("\033[30m\033[36m["__FILE__"](%05d) - %s]\n\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)



#define CDEBUG_SFL(cmdt, format,...)      do{if((cmdt)) printf("["__FILE__"](%05d) - %s]  "format"\n", __LINE__, ##__VA_ARGS__ ,  __FUNCTION__)
#define CDEBUG_SFLR(cmdt, format,...)     do{if((cmdt)) printf("\033[30m\033[31m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_SFLG(cmdt, format,...)     do{if((cmdt)) printf("\033[30m\033[32m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_SFLY(cmdt, format,...)     do{if((cmdt)) printf("\033[30m\033[33m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_SFLP(cmdt, format,...)     do{if((cmdt)) printf("\033[30m\033[35m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)
#define CDEBUG_SFLB(cmdt, format,...)     do{if((cmdt)) printf("\033[30m\033[36m["__FILE__"](%05d) - %s]\033[0m  "format"\n", __LINE__, __FUNCTION__,##__VA_ARGS__);}while(0)

#define CSC_CLEAR(cmdt)                   do{if((cmdt)) printf("\033[2J");}while(1)

#else

#define CDEBUG(cmdt, format,...)
#define CDEBUG_RED(cmdt, format,...)
#define CDEBUG_GREEN(cmdt, format,...)
#define CDEBUG_YELLOW(cmdt, format,...)
#define CDEBUG_PURP(cmdt, format,...)
#define CDEBUG_BLUE(cmdt, format,...)

#define CDEBUG_FL(cmdt,  format,...)
#define CDEBUG_FLR(cmdt, format,...)
#define CDEBUG_FLG(cmdt, format,...)
#define CDEBUG_FLY(cmdt, format,...)
#define CDEBUG_FLP(cmdt, format,...)
#define CDEBUG_FLB(cmdt, format,...)

#define CDEBUG_SFL(cmdt,  format,...)
#define CDEBUG_SFLR(cmdt, format,...)
#define CDEBUG_SFLG(cmdt, format,...)
#define CDEBUG_SFLY(cmdt, format,...)
#define CDEBUG_SFLP(cmdt, format,...)
#define CDEBUG_SFLB(cmdt, format,...)
#define  CSC_CLEAR(format,...)
#endif  /* __CDEBUG_PRINTF__*/


#ifdef  __DEBUG_PERROR__
#define PERROR(string)   do{ perror(string); }while(0)
#else
#define  PERROR(format,...)
#endif  /* __DEBUG_PERROR__*/

#ifdef  __CDEBUG_PERROR__
#define CPERROR(       cmdt, string)   do{if((cmdt)) perror(string); }while(0)
#else
#define  CPERROR(format,...)
#endif  /* __CDEBUG_PERROR__*/

